package com.hl.card.award.controller;

import com.hl.card.common.persistence.model.User;
import com.hl.card.common.util.ResponseObject;
import com.hl.card.modular.pack.dto.AwardUser;
import com.hl.card.award.service.IRewardByTrans;
import com.hl.card.award.service.LoginUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * java类简单作用描述
 *
 * @ProjectName: distdev
 * @Package: com.hl.card.modular.pack.controller
 * @ClassName: ${TYPE_NAME}
 * @Description: java类作用描述
 * @Author: 作者姓名
 * @CreateDate: 2018/7/9 17:45
 * @UpdateUser: Neil.Zhou
 * @UpdateDate: 2018/7/9 17:45
 * @UpdateRemark: The modified content
 * @Version: 1.0
 * <p>Copyright: Copyright (c) 2018</p>
 */
@RestController
@RequestMapping("/api")
public class LoginRewardController {
    @Autowired
    private LoginUserService rewardByTrans;

    @PostMapping(value = "/login/reward")
    public ResponseObject reward(String awardUser) {
        return rewardByTrans.reward(awardUser);
    }

    @PostMapping(value = "/login/getUserByRegCode")
    public ResponseObject getUserByRegCode(String regCode) {
        ResponseObject res = new ResponseObject();
        res.setErroCode(1);
        res.setData("获取用户失败");
        User user = rewardByTrans.getUserByRegCode(regCode);
        if(user != null) {
            res.setErroCode(0);
            res.setData(user);
        }
        return res;
    }

    @PostMapping(value = "/login/checkRegCode")
    public ResponseObject checkRegCode(String regCode) {
        ResponseObject res = new ResponseObject();
        res.setErroCode(1);
        res.setData(false);
        boolean result = rewardByTrans.checkRegCode(regCode);
        if(result) {
            res.setErroCode(0);
            res.setData(result);
        }
        return res;
    }
}
